<template>
  <div class="app-container">
    <div class="filter-container">
      <el-row>
        <el-col :span="6">交易额：{{analysisData.capital}}</el-col>
        <el-col :span="6">
          利润：

          <el-tag v-if="analysisData.profit < 0" effect="dark" type="success">￥{{ analysisData.profit }}</el-tag><el-tag effect="dark" type="danger" v-else >￥{{ analysisData.profit }}</el-tag>
        </el-col>
        <el-col :span="6">浮动盈亏：{{analysisData.marketProfit}}</el-col>
      </el-row>      
      
      
      
    </div>
      <el-row>
  <el-col :span="22">
    
     <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="合约" prop="symbol">
          <el-input v-model="filterForm.symbol" clearable placeholder="合约" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="状态" prop="accountStatus">
          
      <el-radio-group v-model="filterForm.accountStatus">
        <el-radio-button label="0">全部</el-radio-button>
        <el-radio-button label="3">已平仓</el-radio-button>
        <el-radio-button label="2">交易中</el-radio-button>
      </el-radio-group>
        </el-form-item>
        <el-form-item label="周期" prop="scale">
          
      <el-radio-group v-model="filterForm.scale">
        <el-radio-button label="0">全部</el-radio-button>
        <el-radio-button label="15">M15</el-radio-button>
        <el-radio-button label="1440">D1</el-radio-button>
      </el-radio-group>
        </el-form-item>
      </el-form>
  </el-col>
  <el-col :span="2">
    <el-button type="primary" @click="handleFilter">搜索</el-button>
  </el-col>
</el-row>
      <el-row>
  <el-col :span="24">
      <el-table
      :data="accountList"
      border
      style="width: 100%">
      <el-table-column
        label="合约" width="300">
        <template slot-scope="{row}">
          <div @click="handleDetail(row)">{{ row.symbol }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="资产">
        <template slot-scope="{row}">
          <div>{{ row.costPrice/100 }}</div>
          <div>{{ row.capital }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="量">
        <template slot-scope="{row}">
          <div>{{ row.quantity }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="可用资金"
        width="120">
        <template slot-scope="{row}">
          <span>{{ row.usable }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="总金额"
        width="100">
        <template slot-scope="{row}">
          <span>{{ row.amount }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="浮动利润"
        width="100">
        <template slot-scope="{row}">
          <span v-if="row.accountStatus == 2">{{ row.marketProfit/100 }}</span>
          <span v-if="row.accountStatus == 3">{{ row.profit/100 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="状态"
        width="100">
        <template slot-scope="{row}">
          <span v-if="row.accountStatus == 2" style="color:green;">交易中</span>
          <span v-else-if="row.accountStatus == 3" style="color:red;">已平仓</span>
          <span v-else style="color:green">未知</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="createdAt"
        label="创建时间"
        width="160">
      </el-table-column>
      </el-table>
  </el-col>
</el-row>
      
    
    <pagination v-show="total>0" :total="total" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getAccountList" />

  </div>
</template>

<script>
//import { getFaultinessList,  removeFaultinessByID, changeFaultinessStatusByID } from '@/api/development/faultiness'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getAccountList} from '@/api/strategy/account'
export default {
  name: 'accountAdmin',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      
      socket:"",
      tableKey: 0,
      dataType:"1",
      windowHeight:"800",
      allowedLoaded:false,
      allowedLoadedRealtime:false,
      symbolOptions:[],
      signalFilterForm:{},
      accountList:[],
      total: 0,
      listLoading: false,
      connected:"loading",
      analysisData:{
        profit:0,
        marketProfit:0,
        capital:0
      },
      filterForm: {
        page: 1,
        size: 10,
        accountStatus:0,
        symbol:''
      }
    }
  },
  created() {
    //开启行情自动读取
    this.allowedLoaded = true;
    this.allowedLoadedRealtime = true;
    this.getAccountList()
  },
  mounted(){
  },
  destroyed(){
  },
  methods: {
    getAccountList:function(){
      let _this = this;
      console.log("期权",_this.filterForm)
      getAccountList(_this.filterForm).then((response) => {
        console.log("getAccountList",response)
          if (response.code === 200) {
            this.accountList = response.data.list
            this.total = response.data.total
            this.analysisData = response.data.analysisData
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleRefreshButton:function(){
        this.getList()
    },
    handleDetail:function(item){
      window.localStorage.setItem('prevUrl',window.location.href)
      this.$router.push({ path:'/quantization/account-delivery', query: {"accountID":item.ID} })
    },
    handleFilter() {
      console.log("合约变动")
      this.filterForm.page = 1
      this.getAccountList()
    },
    sortChange(data) {
      const { prop, order } = data
      if (prop === 'id') {
        this.sortByID(order)
      }
    },
    sortByID(order) {
      if (order === 'ascending') {
        this.filterForm.sort = '+id'
      } else {
        this.filterForm.sort = '-id'
      }
      this.handleFilter()
    }
  }
}
</script>
<style>

</style>